package com.fhzn.auth.context;

/**
 * @author fhzn
 */
public final class DataSourceRoutingKeyContext {

    private static final String DEFAULT_DATASOURCE = "defaultDataSource";
    private final static ThreadLocal<String> CONTEXT = ThreadLocal.withInitial(() -> DEFAULT_DATASOURCE);

    private DataSourceRoutingKeyContext() {
    }

    public static void setDataSourceRoutingKey(String dataSourceRoutingKey) {
        CONTEXT.set(dataSourceRoutingKey);
    }

    public static String getDataSourceRoutingKey() {
        return CONTEXT.get();
    }

    public static String removeDataSourceRoutingKey() {
        String routingKey = CONTEXT.get();
        CONTEXT.remove();
        return routingKey;
    }

}